/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.documentary.presenter;

import com.suozhang.framework.entity.bo.UserInfoBo;
import com.yiqi.lottery.entity.bo.HallUserBo;
import com.yiqi.lottery.entity.bo.LotteryBo;
import com.yiqi.lottery.entity.bo.OrderBo;
import com.yiqi.lottery.feature.documentary.contract.PersonContract;
import com.yiqi.lottery.feature.documentary.contract.RankContract;
import com.yiqi.lottery.feature.documentary.dependencies.home.DaggerFollowPresenterComponent;
import com.yiqi.lottery.feature.documentary.dependencies.rank.DaggerRankPresenterComponent;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import javax.inject.Inject;

import java.util.List;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class RankPresenter implements RankContract.Presenter {

    private RankContract.View mView;

    @Inject

    RankContract.Model mModel;


    public RankPresenter(RankContract.View mView) {
        this.mView = mView;
        DaggerRankPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getHallList(int type, int page) {
        mModel.getRankList(type, page).compose(mView.bindToLife())
                .subscribe(new Observer<List<LotteryBo>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(List<LotteryBo> s) {
                        mView.dismissLoading();
                        if (s.size() > 0) {
                            mView.showRankListSuccess(s);
                        } else {
                            mView.showRankListEmpty();
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoading();
                        mView.showRankListError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                    }
                });
    }

    @Override
    public void getHallListMore(int type, int page) {
        mModel.getRankList(type, page).compose(mView.bindToLife())
                .subscribe(new Observer<List<LotteryBo>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(List<LotteryBo> s) {
                        mView.showRankListMoreSuccess(s);
                    }

                    @Override
                    public void onError(Throwable e) {

                        mView.showRankListMoreError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
